import numpy as np
import pandas as pd
from package_ternary_calculation import thermodynamic
from package_ternary_calculation import kinetic

thermodynamic_database = "TCNI10"
kinetic_database = "MOBNI5"

elements = ["Ni", "Al", "Mo"]  # 0,1,2 namely A,B,C
phases = {'DIS_FCC_A1': 0, 'FCC_L12': 1, 'BCC_A2': 0, 'BCC_B2': 1}

B_diff_pot_range = np.linspace(-1e5, 1e5, 500)
C_diff_pot_range = np.linspace(-1e5, 1e5, 500)

for temp in range(1273, 1474, 50):
    for target_phase in phases.keys():
        thermodynamicfile = thermodynamic(elements, target_phase, thermodynamic_database,
                                          temp, B_diff_pot_range, C_diff_pot_range, phases[target_phase])
        TF_pd_reader = pd.read_csv(
            thermodynamicfile, header=0, sep=',').interpolate()
        TF_pd_reader.to_csv('pd_'+thermodynamicfile, index=0, sep=',')
        x_B_ = TF_pd_reader['x_'+elements[1]+'_'+target_phase]
        x_C_ = TF_pd_reader['x_'+elements[2]+'_'+target_phase]
        kineticfile = kinetic(elements, target_phase, thermodynamic_database, kinetic_database,
                              temp, B_diff_pot_range, C_diff_pot_range, x_B_, x_C_, phases[target_phase])
        LB_pd_reader = pd.read_csv(
            kineticfile, header=0, sep=',').interpolate()
        LB_pd_reader.to_csv('pd_'+kineticfile, index=0, sep=',')
